class Admin::UmbrellasController < ApplicationController
  layout "maintain"
  # GET /admin/umbrellas
  # GET /admin/umbrellas.json
  def index
    @admin_umbrellas = Admin::Umbrella.all

    respond_to do |format|
      #format.html { render :json => @admin_umbrellas.collect { |au| au.to_jq_upload }.to_json }# index.html.erb
      #format.html { render :json => {:files => @admin_umbrellas.collect { |au| au.to_jq_upload } , :content_type => "text/html", :layout => false }}
      format.html # index.html.erb
      #format.json { render :json => @admin_umbrellas.collect { |au| au.to_jq_upload }.to_json }
    end
  end

  # GET /admin/umbrellas/1
  # GET /admin/umbrellas/1.json
  def show
    @admin_umbrella = Admin::Umbrella.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @admin_umbrella }
    end
  end

  # GET /admin/umbrellas/new
  # GET /admin/umbrellas/new.json
  def new
    @admin_umbrella = Admin::Umbrella.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @admin_umbrella }
    end
  end

  # GET /admin/umbrellas/1/edit
  def edit
    @admin_umbrella = Admin::Umbrella.find(params[:id])
  end

  # POST /admin/umbrellas
  # POST /admin/umbrellas.json
  def create
    @admin_umbrella = Admin::Umbrella.new(params[:admin_umbrella])

    respond_to do |format|
      if @admin_umbrella.save
        format.html { render :json => {:files => [@admin_umbrella.to_jq_upload]} , :content_type => "text/html", :layout => false }
        format.json { render :json => {:files => [@admin_umbrella.to_jq_upload]} } 
      else
        format.html { render action: "new" }
        format.json { render json: @admin_umbrella.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /admin/umbrellas/1
  # PUT /admin/umbrellas/1.json
  def update
    @admin_umbrella = Admin::Umbrella.find(params[:id])

    respond_to do |format|
      if @admin_umbrella.update_attributes(params[:admin_umbrella])
        format.html { redirect_to @admin_umbrella, notice: 'Umbrella was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @admin_umbrella.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /admin/umbrellas/1
  # DELETE /admin/umbrellas/1.json
  def destroy
    @admin_umbrella = Admin::Umbrella.find(params[:id])
    @admin_umbrella.remove_avatar unless @admin_umbrella == nil
    @admin_umbrella.destroy

    respond_to do |format|
      format.html { redirect_to admin_umbrellas_url }
      format.json { head :ok }
    end
  end
end
